//
//  DoubleBtnCell.m
//  Estate
//
//  Created by heyong on 16/9/19.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "DoubleBtnCell.h"

@implementation DoubleBtnCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        self.extraBtn=[[UIButton alloc]initWithFrame:CGRectMake(5, 5, 100, 35)];
        [self.extraBtn setTitle:@"额外巡检" forState:UIControlStateNormal];
        self.extraBtn.titleLabel.font=[UIFont systemFontOfSize:14*BIZ];
        [self.contentView addSubview:self.extraBtn];
        [self.extraBtn addTarget:self action:@selector(extraBtn1:) forControlEvents:UIControlEventTouchUpInside];
        //默认按钮颜色
        [self.extraBtn setTitleColor:UIColorFromRGB(0x787878) forState:UIControlStateNormal];
        //选中按钮颜色
        [self.extraBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        //默认背景图片
        [self.extraBtn setBackgroundImage:[UIImage imageNamed:@"weixuanzhongdise"] forState:UIControlStateNormal];
        //选中背景图片
        [self.extraBtn setBackgroundImage:[UIImage imageNamed:@"xuanzhongdise"] forState:UIControlStateSelected];
        
        self.routineBtn=[[UIButton alloc]initWithFrame:CGRectMake(110, 5, 100, 35)];
        [self.routineBtn setTitle:@"例行巡检" forState:UIControlStateNormal];
        self.routineBtn.titleLabel.font=[UIFont systemFontOfSize:14*BIZ];
        [self.contentView addSubview:self.routineBtn];
        [self.routineBtn addTarget:self action:@selector(routineBtn2:) forControlEvents:UIControlEventTouchUpInside];
        //默认按钮颜色
        [self.routineBtn setTitleColor:UIColorFromRGB(0x787878) forState:UIControlStateNormal];
        //选中按钮颜色
        [self.routineBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        //默认背景图片
        [self.routineBtn setBackgroundImage:[UIImage imageNamed:@"weixuanzhongdise"] forState:UIControlStateNormal];
        //选中背景图片
        [self.routineBtn setBackgroundImage:[UIImage imageNamed:@"xuanzhongdise"] forState:UIControlStateSelected];
    }
    return self;
}

- (void)extraBtn1:(UIButton *)sender{
    if(self.edit){
        sender.selected=YES;
        self.routineBtn.selected=NO;
        if(self.extraClickBtn){
            self.extraClickBtn();
        }
    }
}

- (void)routineBtn2:(UIButton *)sender{
    if(self.edit){
        sender.selected=YES;
        self.extraBtn.selected=NO;
        if(self.rountine){
            self.rountine();
        }
    }
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"btn";
    DoubleBtnCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[DoubleBtnCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

//设置分割线
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect);
       //下分割线
    CGContextSetStrokeColorWithColor(context,[UIColor colorWithRed:0.89 green:0.89 blue:0.90 alpha:1.00].CGColor);
    CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

@end


